﻿function CheckLogin() {
    //获取验证码的值
    var yzm = document.getElementById("yzm").innerHTML;//图片上的验证码
    var in1 = document.getElementById("in1").value.toUpperCase();//用户输入的验证码

    var loginUser = {
        UserAccount: $("#txtUserAccount").val(),
        UserPassword: $("#txtUserPassword").val(),
    }
    $.ajax({
        type: "POST",
        url: "/User/BusinessUserCheck",
        data: loginUser,
        dataType: "json",
        error: function (ajaxExceptionModel) {
            //显示错误
            var obj = JSON.stringify(ajaxExceptionModel.responseText);
            alert(obj.ErrorMessage);
        },
        success: function (result) {

            if (isNaN(result.UserID) || result.UserID == "" || typeof (result.UserID) == "undefined") {
                alert("用户名或密码错误");
                window.location.href = "/Home/BusinessUserLogin";
            } else if (!result.IsValid) {
                alert("当前用户为禁用状态");
                window.location.href = "/Home/BusinessUserLogin";
            } else if (yzm != in1) {
                alert("验证码不正确");
                window.location.href = "/Home/BusinessUserLogin";
            }
            else {
                //登陆成功，设置store
                store.set('UserID', result.UserID);
                alert("登录成功");
                window.location.href = "http://localhost:12470/Home/Index";
            }
        }
    });
}
/*验证码*/
function getyzm() {
    var code;
    function createCode() {
        code = '';
        var codeLength = 4;

        var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
        for (var i = 0; i < codeLength; i++) {
            var index = Math.floor(Math.random() * 36);
            code += random[index];
        }
        document.getElementById("yzm").innerHTML = code;
    }
    createCode();
}